#pragma once

#include "fxcc/core/pch.h"
#include "fxcc/core/Base.h"
#include "fxcc/yml/Serializer.h"

namespace fxcc
{
	struct FXCC_API Cache :public fxcc::Base {


		std::string m_LastOpen;

		struct FXCC_API File :public fxcc::Base
		{
			std::string m_Path;
			int m_ModifyTime;
		};

		std::vector<File> m_Recents;

		int FindIndex(const std::string& path)
		{
			for (int i = 0; i < m_Recents.size(); i++)
			{
				if (m_Recents[i].m_Path == path)
				{
					return i;
				}
			}
			return -1;

		}
		void AddRecentPath(const std::string& path)
		{
			int index = FindIndex(path);
			if (index != -1)
			{
				m_Recents[index].m_ModifyTime = CurrentTime();
			}
			else
			{
				File file;
				file.m_ModifyTime = CurrentTime();
				file.m_Path = path;
				m_Recents.push_back(file);
			}

			std::sort(m_Recents.begin(), m_Recents.end(), [](File a, File b) {return a.m_ModifyTime > b.m_ModifyTime; });
		}
		static int CurrentTime()
		{
			auto now = std::chrono::system_clock::now();
			auto duration = now.time_since_epoch();
			auto millis = std::chrono::duration_cast<std::chrono::milliseconds>(duration).count();
			return static_cast<int>(millis);

		}
	};
};